package cn.edu.tyu.finance.thingstype.servlet;

import cn.edu.tyu.finance.thingstype.domain.Users;
import cn.edu.tyu.finance.thingstype.service.UserServiceImp1;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Userservlet", value = " /Userservlet")
public class Userservlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method");
        if("add".equals(method)) {
            addUser(request,response);
        }
    }
    private void addUser(HttpServletRequest request,HttpServletResponse response){
        String userid = request.getParameter("userid");
        String username = request.getParameter("username");
        String userpsw = request.getParameter("userpsw");
        Users users=new Users();
        users.setUserid(userid);
        users.setUsername(username);
        users.setUserpsw(userpsw);
        UserServiceImp1 userServiceImp1 = new UserServiceImp1();
        int res=0;
        if (res>0){
            //进入查询页面
            try {
                response.sendRedirect("request.getContextPath()+/user?method=query");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            //还是在添加页面
            try {
                response.sendRedirect("request.getContextPath()+/addUser.jsp");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @Override

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
